package com.dhcc.file.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dhcc.file.mapper.FileMapper;
import com.dhcc.file.model.Attach;
import com.dhcc.file.service.FileService;
import com.dhcc.utils.CommonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class FileServiceImpl implements FileService {

    @Autowired
    private FileMapper fileMapper;


    @Override
    public int add(Attach attach) {
        int count = fileMapper.insert(attach);
        return count;
    }

    @Override
    public int del(String id) {
        int count = fileMapper.deleteById(id);
        return count;
    }

    @Override
    public Attach getById(String id) {
        return fileMapper.selectById(id);
    }

    @Override
    public List<Attach> list() {
        QueryWrapper<Attach> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("create_time");
        return fileMapper.selectList(queryWrapper);
    }

    @Override
    public Attach getLikeFileName(String fileName) {
        QueryWrapper<Attach> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("file_name", fileName);
        return fileMapper.selectOne(queryWrapper);
    }

    @Override
    public int upt(Attach attach) {
        return fileMapper.updateById(attach);
    }

    @Override
    public int del() {
        QueryWrapper<Attach> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("create_time", CommonUtils.getNowDetail(), CommonUtils.getNowDetail());
        int count = fileMapper.delete(queryWrapper);
        return count;
    }


}
